package A1动态规划;

public class LC_322零钱兑换_先包后物 {
    public int coinChange(int[] coins, int amount) {
        int max=Integer.MAX_VALUE;
        int[] dp=new int[amount+1];
        dp[0]=0;
        for(int i=1;i<dp.length;i++)
            dp[i]=max;
        for(int j=0;j<=amount;j++)
            for(int i=0;i<coins.length;i++)
                if(j>=coins[i] && dp[j-coins[i]]!=max)
                    dp[j]=Math.min(dp[j-coins[i]]+1,dp[j]);
        return dp[amount]==max?-1:dp[amount];
    }
}
